package com.jjong.Ajax;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONObject;

import com.jjong.dto.BoardDto;
import com.jjong.dto.MembersDto;
import com.jjong.model.JjongBoardManager;
import com.jjong.model.JjongBoardService;
public class MemberAjaxServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    public void doGet(HttpServletRequest request, 
    		HttpServletResponse response) throws ServletException, IOException {
    	doPost(request,response);
	}
    public void doPost(HttpServletRequest request,
    		HttpServletResponse response) throws ServletException, IOException {
    	request.setCharacterEncoding("euc-kr");
    	response.setContentType("text/json; charset=euc-kr");
    	JjongBoardService service = JjongBoardService.getInstance();
    	
    	JjongBoardManager manager=new JjongBoardManager();
		//System.out.println(request.getParameter("id"));
		
    	//String id=request.getParameter("id");
		String email = request.getParameter("email");
    	System.out.println("1: email=  "+email);
		//MembersDto dto =manager.getCustUser( id);
		int count = service.checkEmail(email);		
		Map<String, Integer> map = new HashMap<String, Integer>();
		map.put("count", count);
		System.out.println("2: count=  "+count);
		JSONObject jsonObject = JSONObject.fromObject(map);
		System.out.println("3: "+jsonObject.toString());
		PrintWriter pr= response.getWriter();
		jsonObject.write(pr);
	}
}
